package com.example.springaop.brokerdemo2;

import lombok.val;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-12-27
 * Time: 18:02
 */
public class JDKInvocationHandler implements InvocationHandler {

    private Object target;

    public JDKInvocationHandler(Object target) {
        this.target = target;
    }

    @Override//调用
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //參數分別是：代理，方法，参数
        System.out.println("我是中介，开始代理");
        //通过反射调用被代理的方法
        Object retVal = method.invoke(target, args);
        //代理增强内容
        System.out.println("我是中介，代理结束");
        return retVal;
    }
}
